package cc.minos.components.container
{
	import cc.minos.components.common.Arrangement;
	import flash.display.DisplayObject;
	
	/**
	 * ...
	 * @author Minos
	 */
	public class GridBox extends Container
	{
		protected var _columns:Number = 4;
		
		protected var _horizontalArrangement:String = Arrangement.NONE;
		protected var _verticalArrangement:String = Arrangement.NONE;
		
		public function GridBox()
		{
			super();
			this._type = 'gridbox';
		}
		
		override public function invalidate():void
		{
			var ypos:Number = _paddingTop;
			var xpos:Number = _paddingLeft;
			var heightValues:Array = [];
			var widthValues:Array = [];
			
			for ( var i:int = 0 ; i < numChildren ; i++ )
			{
				var child:DisplayObject = getChildAt( i );
				
				switch ( _horizontalArrangement )
				{
					case Arrangement.TOP: 
						break;
					case Arrangement.BOTTOM: 
						break;
					case Arrangement.CENTER: 
						break;
					default: 
				}
				
				switch ( _verticalArrangement )
				{
					case Arrangement.LEFT: 
						xpos;
						
						break;
					case Arrangement.RIGHT: 
						break;
					case Arrangement.CENTER: 
						break;
					default:
						
				}
				
				child.y = ypos;
				child.x = xpos;
				
				heightValues.push( child.height );
				
				xpos += child.width + _horizontalGap;
				
				if (( i % _columns ) == _columns - 1 )
				{
					ypos += Math.max.apply( null , heightValues ) + verticalGap;
					xpos = _paddingLeft;
					heightValues = [];
				}
			}
			//
			super.invalidate();
		}
		
		public function get columns():Number
		{
			return _columns;
		}
		
		public function set columns( val:Number ):void
		{
			_columns = val;
			invalidate();
		}
		
		public function get verticalArrangement():String
		{
			return _verticalArrangement;
		}
		
		public function set verticalArrangement( value:String ):void
		{
			_verticalArrangement = value;
			invalidate();
		}
		
		public function get horizontalArrangement():String
		{
			return _horizontalArrangement;
		}
		
		public function set horizontalArrangement( value:String ):void
		{
			_horizontalArrangement = value;
			invalidate();
		}
		
		protected function getMaxWidth():Number
		{
			return 0;
		}
		
		protected function getMaxHeight():Number
		{
			return 0;
		}
	
	}

}